﻿using System;
using QFramework;

namespace Survivor
{
    public class ExpUpgradeItem
    {
        public bool UpgradeFinish { get; set; }
        public string Key { get; set; }
        public string Describe => descirbeFunc.Invoke(CurrentLevel);
        
        public int MaxLevel { get; private set; }

        public BindableProperty<int> CurrentLevel = new BindableProperty<int>();

        public BindableProperty<bool> Visible = new BindableProperty<bool>();

        private Action<ExpUpgradeItem, int> onUpgrade;

        private Func<int, string> descirbeFunc;

        public void Upgrade()
        {
            CurrentLevel.Value++;
            onUpgrade?.Invoke(this, CurrentLevel);
            UpgradeFinish = CurrentLevel >= MaxLevel;
        }

        public ExpUpgradeItem WithKey(string key)
        {
            Key = key;
            return this;
        }

        public ExpUpgradeItem WithDescribe(Func<int, string> describeFunc)
        {
            descirbeFunc = describeFunc;
            return this;
        }

        public ExpUpgradeItem OnUpgrade(Action<ExpUpgradeItem, int> upgradeAction)
        {
            onUpgrade = upgradeAction;
            return this;
        }

        public ExpUpgradeItem WithMaxLevel(int maxLevel)
        {
            MaxLevel = maxLevel;
            return this;
        }
    }
}